package exp12;

import java.util.Scanner;

public class Game {
    public static void main(String[] args) {
        final int BOARD_SIZE = 15;
        Gobang game = new Gobang(BOARD_SIZE);//初始化
        game.initBoard();//初始化棋盘
        game.printBoard();//输出棋盘
        System.out.println("选择等级(1: 随机；2：入门；3：高级)：");
        Scanner sc1 = new Scanner(System.in);
        int level = sc1.nextInt();
        System.out.println("你选择了等级：" + level);
        AIPlayer aiPlayer = new AIPlayer(level, BOARD_SIZE);
        int x, y;
        int humanX = -1, humanY = -1;
        while (true) {
            for (int j = 0; ; )//随机生成 x,y 并判断是否可以下棋
            {
                Point position = aiPlayer.getPosition(game.boardStatus, new Point(humanX, humanY, 1));
//                System.out.println(humanX+":"+humanY);
                x = position.x;
                y = position.y;
                if (game.isFill(x, y) == 1) continue;
                else break;
            }
            game.setBoard(0, x, y);
            game.printBoard();
            if (game.isFive()) {
                System.out.println("电脑获胜了");
                break;
            }
            System.out.println("输入落子点(x y)：");

            for (int j = 0; ; j++) {
                humanX = sc1.nextInt() - 1;//读取玩家x,y
                humanY = sc1.nextInt() - 1;
                if (humanX < 0 || humanX > BOARD_SIZE - 1 || humanY < 0 || humanY > BOARD_SIZE - 1 || game.isFill(humanX, humanY) == 1)//判断输入是否合法
                {//包括坐标的准确性 和 该点是否已经有棋子
                    System.out.println("请重新输入");
                    continue;
                } else break;
            }
            game.setBoard(1, humanX, humanY); // 添加玩家棋子
            if (game.isFive()) //判断玩家是否5连
            {
                System.out.println("你获胜了");
                game.printBoard();
                break;
            }

        }
    }
}
